package com.example.t10v32;

import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ListView;
import javafx.scene.control.TextField;

public class HelloController {

    @FXML
    private ResourceBundle resources;

    @FXML
    private URL location;

    @FXML
    private Button addStudentBtn;

    @FXML
    private TextField addStudentTF;

    @FXML
    private TextField averageGradeTF;

    @FXML
    private TextField nTF;

    @FXML
    private Button solveBtn;

    @FXML
    private ListView<String> studentListView;

    @FXML
    private ListView<String> resStudents;

    @FXML
    void addStudentClick(ActionEvent event) {
        String[] input = addStudentTF.getText().split(" ");
        Student student = new Student(input[0], Integer.parseInt(input[1]), Double.parseDouble(input[2]));
        students.add(student);
        studentListView.getItems().add(addStudentTF.getText());
    }

    @FXML
    void solveClick(ActionEvent event) {
        List<Student> res = new Solution().solve(students, Double.parseDouble(averageGradeTF.getText()), Integer.parseInt(nTF.getText()));
        for (var i : res) {
            resStudents.getItems().add(i.toString());
        }
    }

    private List<Student> students = new ArrayList<>();

    @FXML
    void initialize() {
        assert addStudentBtn != null : "fx:id=\"addStudentBtn\" was not injected: check your FXML file 'hello-view.fxml'.";
        assert addStudentTF != null : "fx:id=\"addStudentTF\" was not injected: check your FXML file 'hello-view.fxml'.";
        assert averageGradeTF != null : "fx:id=\"averageGradeTF\" was not injected: check your FXML file 'hello-view.fxml'.";
        assert nTF != null : "fx:id=\"nTF\" was not injected: check your FXML file 'hello-view.fxml'.";
        assert solveBtn != null : "fx:id=\"solveBtn\" was not injected: check your FXML file 'hello-view.fxml'.";
        assert studentListView != null : "fx:id=\"studentListView\" was not injected: check your FXML file 'hello-view.fxml'.";
        assert resStudents != null : "fx:id=\"resStudents\" was not injected: check your FXML file 'hello-view.fxml'.";
    }

}
